﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using System.ServiceModel;
using System.Data.Services.Common;
using FluentlyDo;
using FluentlyDo.Entities;

namespace Fluent.DataServices
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class FluentDataService : DataService<ServiceAdapter>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
        {
             config.SetEntitySetAccessRule("People", EntitySetRights.AllRead);            
        }
    }    
    public class ServiceAdapter
    {
        private PersonRepository _personRepository;
        public ServiceAdapter()
        {
            SessionManager manager = new SessionManager();
            _personRepository = new PersonRepository(manager.CreateSessionFactory());
        }
        public IQueryable<Person> People
        {
            get
            {
                return _personRepository.GetAll(); 
            }
        }       
    }
}
